<template>
  <view class="shop-car">
    <commonCar :list="goodsProducts" @delect="delect" @accounts="accounts"></commonCar>
  </view>
</template>

<script>
import commonCar from './components/shopCar.vue';
export default {
  data() {
    return {
      goodsProducts: []
    };
  },
  components: {
    commonCar
  },
  methods: {
    delect(e) {
      console.log(e);
      let id = [];
      e.map((i, k) => {
        i.goods.map((m) => {
          console.log(m);
          id.push(m.shopping_id);
        });
      });
      this.api({
        url: '/api//shop/delShopping',
        method: 'post',
        data: {
          ids: id
        }
      }).then((res) => {
        uni.showToast({
          title: res.msg,
          icon: 'none'
        });
        this.getcar();
      });
    },
    accounts(e) {
      console.log(e);
      let arr = [];
      e.map((i, k) => {
        if (i.checked == 2) {
          i.goods.map((n) => {
            arr.push(n);
          });
        }
      });
      this.api({
        url: '/api//shop/preOrder',
        method: 'post',
        data: {
          goods: JSON.stringify(arr)
        }
      }).then((res) => {
        uni.navigateTo({
          url: '/shop/queorder/queorder?type=' + JSON.stringify(res.data)
        });
      });
    },
    getcar() {
      this.api({
        url: '/api/shop/getShoppingList',
        method: 'post'
      }).then((res) => {
        this.goodsProducts = res.data;
      });
    }
  },
  onShow() {
    this.getcar();
  }
};
</script>

<style lang="scss" scoped>
.shop-car {
  width: 750rpx;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #f5f5f5;
}
</style>
